package cn.echo.modules.sys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.echo.modules.sys.entity.SiteCategory;
import cn.echo.modules.sys.service.SiteCategoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by LSF_ on 2017/5/13.
 */
@WebServlet("/siteCategory")
public class SiteCategoryServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //pageNum第几页
        //pageSize每页多少条数据

        Integer pageNum = 1;
        try {
            pageNum = Integer.parseInt(req.getParameter("pageNum"));
        } catch (Exception e) {
            e.printStackTrace();
            pageNum=1;
        }
         //1:设置页码参数
        PageHelper.startPage(pageNum,3);




        SiteCategoryService siteCategoryDao= new SiteCategoryService() ;
        PrintWriter printWriter=resp.getWriter();
        SiteCategory siteCategory= new SiteCategory();


        List<SiteCategory> list =siteCategoryDao.findAllByIf(siteCategory);
        //2:把list集合放到PageInfo
        PageInfo pageInfo = new PageInfo(list);
        req.setAttribute("page",pageInfo);
        req.getRequestDispatcher(req.getContextPath()+"/siteCategoryList.jsp").forward(req,resp);
//        printWriter.print(list);
//
//        printWriter.flush();
//        printWriter.close();

    }
}
